package jmine.tec.hydra.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import jmine.tec.hydra.domain.enumx.HydraCommentOrigin;
import jmine.tec.persist.annotation.Constraint;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Type;
import org.hibernate.validator.NotNull;

import bancosys.tec.utils.date.Timestamp;

/**
 * @author lundberg
 */
@Embeddable
public class HydraComment implements Serializable {

    private static final int COMMENT_LENGTH = 1024;

    private HydraCommentOrigin origin;

    private Timestamp time;

    private String author;

    private String comment;

    /**
     * Construtor
     */
    public HydraComment() {
        // OK
    }

    /**
     * Cria um HydraComment
     * 
     * @param origin origin
     * @param time time
     * @param author author
     * @param comment comment
     */
    public HydraComment(HydraCommentOrigin origin, Timestamp time, String author, String comment) {
        super();
        this.origin = origin;
        this.time = time;
        this.author = author;
        this.comment = StringUtils.abbreviate(comment, COMMENT_LENGTH);
    }

    /**
     * @return the origin
     */
    @NotNull
    @Column(name = "ORIG_COMMENT", nullable = false)
    @Constraint(suffix = "0")
    public HydraCommentOrigin getOrigin() {
        return this.origin;
    }

    /**
     * @return the time
     */
    @NotNull
    @Column(name = "TIME_COMMENT", nullable = false)
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    public Timestamp getTime() {
        return this.time;
    }

    /**
     * @return the author
     */
    @NotNull
    @Column(name = "AUTOR_COMMENT", length = 100, nullable = false)
    public String getAuthor() {
        return this.author;
    }

    /**
     * @return the comment
     */
    @NotNull
    @Column(name = "CONTENT", nullable = false, length = COMMENT_LENGTH)
    public String getComment() {
        return this.comment;
    }

    /**
     * @param origin the origin to set
     */
    public void setOrigin(HydraCommentOrigin origin) {
        this.origin = origin;
    }

    /**
     * @param time the time to set
     */
    public void setTime(Timestamp time) {
        this.time = time;
    }

    /**
     * @param author the author to set
     */
    public void setAuthor(String author) {
        this.author = author;
    }

    /**
     * @param comment the comment to set
     */
    public void setComment(String comment) {
        this.comment = StringUtils.abbreviate(comment, COMMENT_LENGTH);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return String.format("%s: %s", this.getAuthor(), this.getComment());
    }
}
